#include "mainwidget.h"

#include <QApplication>
#include "debug.h"
#include "loginwidget.h"
#include "model/datacenter.h"
#include "network/netclient.h"

//日志重定向
FILE *output = NULL;
void msgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    QByteArray localMsg = msg.toUtf8();
    fprintf(output, "[%s:%d] %s\n", context.file, context.line,localMsg.constData());
    fflush(output);
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

#if DEPLOY
    output = fopen("./log.txt", "a"); //重定向于⽂件
    //注册回调函数，完成向文件中写的功能
    qInstallMessageHandler(msgHandler);
#endif

#if TEST_SKIP_LOGIN
    MainWidget* w = MainWidget::getInstance();
    w->show();
#else
    LoginWidget* loginWidget = new LoginWidget(nullptr);
    loginWidget->show();
#endif


#if TEST_INIT_FILE
    model::DataCenter* dataCenter = model::DataCenter::getInstance();
    dataCenter->loadDataFromFile();
#endif

#if TEST_SERVER
    // network::NetClient netClient(nullptr);
    // netClient.ping();
    model::DataCenter* dataCenter = model::DataCenter::getInstance();
    dataCenter->pingHttp();
#endif
    return a.exec();
}
